package org.sninwo.lnbook.book.dao;

import org.sninwo.lnbook.base.hibernate.HibernateDao;
import org.sninwo.lnbook.book.entity.Book;
import org.sninwo.lnbook.book.entity.Original;
import org.springframework.stereotype.Component;

@Component
public class OriginalDao extends HibernateDao<Original, Long> {
	/**
	 * 通过Book对象保存或添加原文对象，没有设置Book对象的originalId。
	 * @param book Book对象
	 * @param typeName 类型名称
	 */
	public Original saveFormBook(Book book, String typeName){
		Original original = new Original();
		original.setId(book.getOriginalId());
		original.setBookId(book.getId());
		original.setContent(typeName + "\n" + book.toOriginal());
		save(original);
		book.setOriginalId(original.getId()); //同时更新book
		return original;
	}
}
